<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.springframework.org/schema/data/jaxb">
<head>
    <title>Contact</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">
    <meta name="keywords" content=""/>
    <script type="application/x-javascript">
        addEventListener("load", function () {
            setTimeout(hideURLbar, 0);
        }, false);

        function hideURLbar() {
            window.scrollTo(0, 1);
        }
    </script>
    <link th:href="@{/css/bootstrap.css}" rel="stylesheet" type="text/css" media="all"/>
    <link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" media="all"/>
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet">
    <script th:src="@{/js/jquery-2.2.3.min.js}"></script>
    <script th:src="@{/js/bootstrap.js}"></script>
</head>
<body>
<div th:replace="embed/head::head"></div>
<div class="contact agileits">
    <div class="container">
        <h2 class="agileits-title">联系我们</h2>
        <div class="contact-agileinfo">
            <div class="col-md-7 contact-form wthree">
                <form id="contactForm" onsubmit="return false;" >
                    <input type="text" name="visitorName" class="contactF" placeholder="姓名" required >
                    <input type="email" name="visitorLink" class="email contactF" placeholder="邮箱" required >
                    <textarea placeholder="留言" name="content" class="contactF" required ></textarea>
                    <input type="submit" value="提交" id="say" onclick="submitComment()">
                </form>
            </div>
            <div class="col-md-4 contact-right wthree">
                <div class="contact-text w3-agileits">
                    <h4>联系方式 :</h4>
                    <p><i class="fa fa-map-marker"></i><span th:text="${company.address}"></span></p>
                    <p><i class="fa fa-phone"></i> 电话1 : <span th:text="${company.phone1}"></span></p>
                    <p><i class="fa fa-fax"></i> 电话2 : <span th:text="${company.phone2}"></span></p>
                    <p><i class="fa fa-envelope-o"></i> 邮箱 : <a th:href="|mailto:${company.mail}|" th:text="${company.mail}">mail@example.com</a>
                    </p>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<div class="map w3layouts">
</div>
<div id="messageBox" style="display:none;"></div>
<div th:include="embed/articles::articles"></div>
<div th:include="embed/company::companyInfo"></div>
<div th:include="embed/buriedpoint::buriedpoint"></div>
<script type="application/javascript">
    $.fn.serializeObject = function()
    {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
    function submitComment(){
        var checkForm = $("textarea[name='content']")[0].checkValidity()
            && $("input[name='visitorName']")[0].checkValidity()
            && $("input[name='visitorLink']")[0].checkValidity();
        if(checkForm === true){
            var data = $("#contactForm").serializeObject();
            $("#say").attr("disabled", true);
            $.ajax({
                url : "/external/sayHello",
                data : data,
                dataType : "json",
                success : function(result){
                    if(!result.success){
                        alert(result.msg);
                    }else{
                        $("#say").attr("disabled", false);
                        alert("提交成功");
                    }
                },
                error : function(){
                    alert("未知错误, 稍后重试.");
                }
            });
        }
        return false;
    }
</script>
</body>
</html>